package day08_stream_file_charset.com.itheima.d3_recursion;

import java.io.File;
import java.io.IOException;

public class Test6_FileSearch {
    public static void main(String[] args) throws IOException {
        File dir = new File("D:/");
        searchFile(dir, "QQ.exe");
    }

    public static void searchFile(File dir, String fileName) throws IOException {
        if (dir == null || fileName == null || !dir.exists() || dir.isFile()){
            return;
        }
        File[] files = dir.listFiles();
        if (files != null && files.length > 0){
            for (File file : files) {
                if (file.isFile()){
                    if (file.getName().contains(fileName)){
                        System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());
                        Runtime r = Runtime.getRuntime();
                        r.exec(file.getAbsolutePath());
                    }else {
                        searchFile(file,fileName);
                    }
                }
            }
        }
    }
}
